package com.yanfan.energy.controller;

import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.energy.domain.TemplateEnergy;
import com.yanfan.energy.service.EnergyTemplateService;
import com.yanfan.energy.service.TemplateEnergyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.format.DateTimeFormatter;

/**
 * @author caijinkang
 * @date 2022年09月28日 15:40
 */
@RestController
@RequestMapping("/energy")
@Api(tags = "能耗模板配置")
public class EnergyTemplateController {

    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");

    @Autowired
    private EnergyTemplateService energyTemplateService;

    @Autowired
    private TemplateEnergyService templateEnergyService;


    @GetMapping("/findEnergyTemplate")
    @ApiOperation("查询能效模板配置")
    public AjaxResult findEnergyTemplate(@ApiParam(name = "name", value = "名称") @RequestParam(required = false) String name, @ApiParam(name = "number", value = "编号") @RequestParam(required = false) String number, @ApiParam(name = "type", value = "类型") @RequestParam(required = false) Integer type, @ApiParam(name = "grade", value = "等级") @RequestParam(required = false) Integer grade, @ApiParam(name = "currPage", value = "当前页") @RequestParam int currPage, @ApiParam(name = "pageSize", value = "当前页条数") @RequestParam int pageSize) {
        return energyTemplateService.findEnergyTemplate(currPage, pageSize, name, number, type, grade);
    }


    @PostMapping("/addEnergyTemplate")
    @ApiOperation("新增月能耗业绩")
    public AjaxResult add(@ApiParam(name = "templateEnergy", value = "设置对象") @RequestBody TemplateEnergy templateEnergy) {
        return templateEnergyService.insert(templateEnergy);
    }

    @PutMapping("/updateEnergyTemplate")
    @ApiOperation("编辑月能耗业绩")
    public AjaxResult edit(@ApiParam(name = "templateEnergy", value = "设置对象") @RequestBody TemplateEnergy templateEnergy) {
        return templateEnergyService.update(templateEnergy);
    }

    @DeleteMapping("/deleteEnergyTemplate")
    @ApiOperation("删除月能耗业绩")
    public AjaxResult deleteById(@ApiParam(name = "templateId", value = "模板ID") @RequestParam Integer id) {
        return templateEnergyService.deleteById(id);
    }

    @GetMapping("/findEnergyTemplatePullDown")
    @ApiOperation("能效模板下拉列表")
    public AjaxResult findEnergyTemplatePullDown() {
        return templateEnergyService.findEnergyTemplatePullDown();
    }


}
